//=============================================================================
//                              TestEtc.c
//=============================================================================
// AUTHOR      : XENER.COM | snoin
// DATE        : 2000.07.12
// DESCRIPTION : 
//=============================================================================
#define _TestEtc_c_

//=============================================================================
//                               I N C L U D E
//=============================================================================
#include	"HsimIncl.h"

//=============================================================================
//                              C O N S T A N T
//=============================================================================
#define LOAD_TID	100

#define EXIT_CMD_TYPE	11
#define LOAD_CMD_TYPE	12
#define STOP_CMD_TYPE	13

//=============================================================================
//                    C L A S S   A N D   S T R U C T U R E
//=============================================================================

//=============================================================================
//                               M A C R O
//=============================================================================

//=============================================================================
//                      S T A T I C   V A R I A B L E
//=============================================================================
static xui32	load_tid = 0;

//=============================================================================
//                       S T A T I C   F U C T I O N
//=============================================================================
Boolean cbLoadTimer(xui32 sigId, void *msg, xi32 m_size);


void testHandle(SkWatcher *watcher)
{
	ClientServerIPC 	mmc;
	xi32	parPos = 0, rval, tod[7];
	xc8		c;
	xc8		*readData = watcher->mReadBuff;
	xc8		*token = NULL;
	GenString			*string = NULL;
	GenStringPList		*argList = NULL;

	if (strcmp(readData, "\n") == 0) {
		printf("%s >>", oamHostSysName);
		fflush(stdout);
		return;
	}
	memset((xc8 *)&mmc, 0, sizeof(mmc));
	rval = GetTod(tod);
	mmc.overflow = uFalse;
	mmc.next = uFalse;
	mmc.PacketNo = 1;
	mmc.usrIndex = gIndex;
	sprintf(mmc.usrName, "%s", gUsrId);
	mmc.usrType = CLI_USER;
	mmc.dataType = TEXT_CMD;

	for (int i=0; i<strlen(readData); i++) {
		c = readData[i];
		mmc.DataUnit[i] = c;
	}
	mmc.DataUnit[strlen(mmc.DataUnit)] = '\n';

	printf("\n++++++++++++++++++++++++++++++++\n");
	printf("userIndex: %d, usrName: %s\n", gIndex, gUsrId);
	printf("SEND DATA: %s\n", mmc.DataUnit);
	printf("\++++++++++++++++++++++++++++++++\n");

	SendMsgProc(UserInputStr, (xc8 *) &mmc, sizeof(mmc), g_HsmbEntId);
}

void testLogout(SkWatcher *watcher, GenStringPList *argList)
{
	GenString			*string;
	ClientServerIPC		mmc;
	GUI_Login      		 guiLogin;

	mmc.overflow = uFalse;
	mmc.next     = uFalse;
	mmc.PacketNo = 1;
	mmc.usrType  = CLI_USER;
	mmc.dataType = LOGOUT;
	memset(guiLogin.UserName, 0, sizeof(guiLogin.UserName));
	memset(guiLogin.oldpasswd, 0, sizeof(guiLogin.oldpasswd));

	bcp(mmc.DataUnit, (xc8 *)&guiLogin, sizeof(GUI_Login));
	SendMsgProc(LoginLogout, (xc8 *) &mmc, sizeof(ClientServerIPC), g_HsmbEntId);
}

void testLoad(SkWatcher *watcher, GenStringPList *argList)
{
	GenString   *string = NULL;
	xi32	interval = 0;
	xi32	number = 0;

	argList->nth(&string, 0);
	interval = atoi(string->val);

	argList->nth(&string, 1);
	number = atoi(string->val);

	load_tid = skTmCycle(g_tmAddr, interval, SKTM_MSEC, 0, number, LOAD_TID,
						(xc8 *)NULL, 0, cbLoadTimer);
}

void testStop(SkWatcher *watcher, GenStringPList *argList)
{
	if (load_tid > 0) {
		skTmCancel(g_tmAddr, load_tid);
		load_tid = 0;
	}
}

Boolean cbLoadTimer(xui32 sigId, void *msg, xi32 m_size)
{
	ClientServerIPC 	mmc;
	memset((xc8 *)&mmc, 0, sizeof(mmc));

	if (sigId != LOAD_TID) {
		printf("\t unknown timer id\n");
		return uTrue;
	}

	mmc.overflow = uFalse;
	mmc.next = uFalse;
	mmc.PacketNo = 1;
	mmc.usrIndex = gIndex;
	sprintf(mmc.usrName, "%s", gUsrId);
	mmc.usrType = CLI_USER;
	mmc.dataType = TEXT_CMD;

	sprintf(mmc.DataUnit, "test-mmc-cmd:kjjeong;\n");
	SendMsgProc(UserInputStr, (xc8 *) &mmc, sizeof(mmc), g_HsmbEntId);
		
	return uTrue;
}
